package outputStream;

import java.io.*;

/**
 * @author 培培
 * @condition 努力学习中
 *
 * 字节流可以操作二进制文件，可以操作文本文件
 */
public class BufferedCopy02 {
    public static void main(String[] args) {
        String srcFilePath = "d:by.png";
        String destFilePath = "d:newby.png";

        //创建对象
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;

        try {
            //因为 FileInputStream 是 InputStream 的子类
            bis = new BufferedInputStream(new FileInputStream(srcFilePath));
            bos = new BufferedOutputStream(new FileOutputStream(destFilePath));

            //循环读取文件，并写入到 destFilePath
            byte[] buff = new byte[1024];
            int readLen = 0;
            //当返回-1 时，就表示文件读取完毕
            while ((readLen = bis.read(buff)) != -1){
                bos.write(buff,0,readLen);
            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bis != null){
                    bis.close();
                }
                if(bos != null){
                    bos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
